package org.leyi.shop.controller;

import jakarta.annotation.Resource;
import org.leyi.shop.common.response.BaseResponse;
import org.leyi.shop.model.bo.OrderDelayItem;
import org.leyi.shop.service.OrderService;
import org.leyi.shop.util.BaseResponseUtils;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("order")
@CrossOrigin(allowCredentials = "true",origins = {"http://localhost:5173"})
public class OrderController {
    @Resource
    private OrderService orderService;

    /**
     * description: 在延迟队列里面增加一个订单
     *
     * @param orderDelayItem 订单BO实体
     * @return BaseResponse
     * @author lenovo
     * create 2024/5/8-20:52
     */
    @PostMapping("")
    public BaseResponse<OrderDelayItem> addOrder(@RequestBody OrderDelayItem orderDelayItem) {
        return BaseResponseUtils.success(orderService.addOrder(orderDelayItem), "添加成功了");
    }

    /**
     *
     * description: 用户付款订单接口
     * @param orderId 订单生成的id
     * @return BaseResponse<OrderDelayItem>
     * @author  lenovo
     * create 2024/5/8-22:41
     */
    @GetMapping("pay/{orderId}")
    public BaseResponse<OrderDelayItem> payOrderById(@PathVariable Long orderId)
    {
         return BaseResponseUtils.success(orderService.payOrder(orderId));
    }
    /**
     * description: 用户取消订单接口
     * @param orderId 订单生成的id
     * @return BaseResponse<OrderDelayItem>
     * @author  lenovo
     * create 2024/5/8-22:40
     */
    @GetMapping("cancel/{orderId}")
    public BaseResponse<OrderDelayItem> cancelOrderById(@PathVariable Long orderId)
    {
        return BaseResponseUtils.success(orderService.cancelOrder(orderId));
    }

}
